package com.atguigu.ssyx.product.controller;

import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.product.config.QiniuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/admin/ssyx/FileUpload")
public class FileUploadController {

    @Autowired
    private QiniuService qiniuService;

    @PostMapping("/upload")
    public Result uploadFile(@RequestParam("file") MultipartFile file) {
        try {
            Map map = qiniuService.uploadFile(file);
            return Result.ok(map);
        } catch (Exception ex) {
            ex.printStackTrace();
            return Result.fail(null);
        }
    }
}
